package com.grf.hadoop.same_friend;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FriendMapper extends Mapper<LongWritable, Text, Text, Text> {

    private Text friend = new Text();
    private Text user = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {
        //
        String line = value.toString();
        String[] fields = line.split(":");
        user.set(fields[0]);
        String[] friends = fields[1].split(",");

        for (String s : friends) {
            friend.set(s);
            context.write(friend, user);
        }
    }

}
